#ifndef 顺序表
#define 顺序表

typedef int ElemType;

#define MaxSize 50

typedef struct
{
    ElemType data[MaxSize];
    int length;
} SqList;

//注意 i 从1开始

bool ListInsert(SqList &L, int i, ElemType e)
{
    if (i < 1 or i > L.length + 1)
        return false;
    if (L.length >= MaxSize)
        return false;
    for (int j = L.length; j >= i; j--)
        L.data[j] = L.data[j - 1];
    L.data[i - 1] = e;
    L.length++;
    return true;
}

bool ListDelete(SqList &L, int i, ElemType &e)
{
    if (i < 1 or i > L.length)
        return false;
    e = L.data[i - 1];
    for (int j = i; j < L.length; j++)
    {
        L.data[j - 1] = L.data[j];
    }
    L.length--;
    return true;
}

int LocateElem(SqList L, ElemType e)
{
    for (int i = 0; i < L.length; i++)
        if (L.data[i] == e)
            return i + 1;
    return 0;
}

#endif